<<C++语言程序设计>>中的第一题,我编了以下程序,可老出错,想请各位大侠帮帮忙!先谢谢了!

来源:百度知道 编辑:UC知道 时间:2024/05/29 03:02:50
(1)设计要求:
假设类名为Welcome,给出主程序如下:
void main()
{welcome we;
welcome you(we);
You.display();D
you.set("Thank you.");
cout<<you.Get()<<endl;
you.talk();
you.display();
}
下面是给出类的定义:
class Welcome{
private:
char str[128];
public:
Welcome(char s[]="welcome!");
Welcome(Welcome &);
void set(char []);
void display();
char *Get();
void talk();
~Welcome();
};
请编写合适的成员函数,使程序的运行结果为:
Welcome!
Thank you.
当输入:How about you?
就输出:How about you?
输入:OK
All right!
Goodbye!
OK
Goodbye!
Goodbye!

我自己编了一个程序,可是老出现下面这个错误,郁闷死我了!
Compiling...
h.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/44.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

我写的程序如下:
#include<iostream>
using namespace std;

我修改了下,下面的代码在Windows XP + VC++6.0下正常运行,直接复制粘贴就行了

有2点是你需要注意的
(1)题目的意思是:
"当输入:"后面的那句"How about you?"和"输入:"后的那句"OK"是由你从键盘中输入的,其它的都由程序自动输出
(2)你存在很多语法错误
比如C++中是分大小写的,可你的代码中大小写不分;
类成员函数的定义格式也不对

建议你先看一下C++基础教材,先掌握语法,模仿教材上的设计

#include<iostream>
#include<cstdio>//函数strcpy(),stcmy()包含在此头文件中
using namespace std;

class Welcome
{
private:
char str[128];
public:
Welcome(char s[]="Welcome!");
Welcome (Welcome &);
void set(char []);
void display();
char *Get();
void talk();
~Welcome();
};
Welcome::Welcome(char s[])//默认参数值在函数声明中已写了,此处若改为char s[]="Welcom!"错
{
strcpy(str,s);//把字符串数组s中的所有字符,拷贝到字符串数组str中
}

Welcome::Welcome(Welcome &c)//拷贝构造函数
{
strcpy(str,c.str);
}

void Welcome::set(char s[])
{
strcpy(st